<template>
	<view class="content">
		<view class="title">子组件B</view>
		<view class="b-box">
			CompA组件传进来的值：
			<view class="box-1">
				<text>{{ result }}</text>
			</view>
		</view>
		<view class="b-box">
			<text class="label">回传值：</text>
			<input type="text" v-model="callbackValue" class="common-box" />
			<button @click="sendOutsize()" size="mini">回传</button>
		</view>
	</view>
</template>

<script>
	export default {
		name: "compB",
		data() {
			return {
				result: '',
				callbackValue: '0595-2788888'
			};
		},
		mounted() {
			uni.$on('getIntent', (msg) => {
				console.log('子组件B收到A的传值：', msg);
				this.result = msg;
			});
		},
		beforeUnmount() {
			uni.$off('getIntent');
		},
		methods: {
			sendOutsize() {
				console.log('子组件B回传给父组件：', this.callbackValue);
				this.$emit('callBackFun', this.callbackValue);
			}
		}
	}
</script>

<style>
	.content {
		background-color: #7097D0;
		display: flex;
		flex-direction: column;
		align-items: center;
		height: 300rpx;
		margin: 50rpx;
	}

	.title {
		font-size: 50rpx;
		text-align: center;
	}

	.b-box {
		font-size: 28rpx;
		margin: 10rpx 0;
		display: flex;
		align-items: center;
		gap: 10rpx
	}

	.box-1 {
		background-color: blue;
		color: #fff;
		padding: 22rpx 100rpx;
		border-radius: 4rpx;
	}

	.label {
		font-size: 28rpx;
		color: #fff;
		white-space: nowrap;
	}

	.common-box {
		flex: 1;
		background-color: #ddd;
		padding: 10rpx ;
		border-radius: 4rpx;
		color: red;
		font-size: 28rpx;
	}
	.common-box:focus {
		background-color: #eee;
	}
</style>